package com.googlecode.FWT.controller
{
	import com.googlecode.FWT.model.ProjectDataProxy;
	import com.googlecode.FWT.view.buttons.back.*;
	import com.googlecode.FWT.view.buttons.clear.ClearButtonMediator;
	import com.googlecode.FWT.view.buttons.print.PrintButtonMediator;
	import com.googlecode.FWT.view.buttons.forward.ForwardButtonMediator;
	import com.googlecode.FWT.view.pageloader.PageLoaderMediator;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;

	public class StartCommand extends SimpleCommand
	{
		/**
		 * Execute the command.
		 * @param notification Body should contain a FWT instance.
		 * @throws Error if incorrect body found in notification.
		 */		
		override public function execute(notification:INotification):void
		{
			var appRef:FWT = notification.getBody() as FWT;
			
			// test correct body
			if(appRef == null)
			{
				throw new Error("Notification body should contain a FWT instance.");
			}
			
			// register proxy instances
			registerProxies();
			
			// register mediators
			// do this after the proxies so data is available
			registerMediators(appRef);
		}
		/**
		 * Register PureMVC proxy instances. 
		 */		
		protected function registerProxies():void
		{
			facade.registerProxy(new ProjectDataProxy());
		}
		
		
		protected function registerMediators(appRef:FWT):void
		{
			facade.registerMediator(new BackButtonMediator(appRef.backBtn));
			facade.registerMediator(new ForwardButtonMediator(appRef.forwardBtn));
			facade.registerMediator(new PageLoaderMediator(appRef.pageLoader));
			facade.registerMediator(new ClearButtonMediator(appRef.clearBtn));
			facade.registerMediator(new PrintButtonMediator(appRef.printBtn));
		}
	}
}